"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PopupMiniLayout = PopupMiniLayout;

var _react = _interopRequireDefault(require("react"));

var _components = require("@tarojs/components");

var _classnames = _interopRequireDefault(require("classnames"));

var _configContext = require("../../../extends/configContext");

var _icon = _interopRequireDefault(require("../../icon"));

var _button = _interopRequireDefault(require("../../button"));

var _noop = require("../../../utils/noop");

var _excluded = ["position", "visible", "onClose", "onCancel", "onSubmit", "maskClosable", "children", "className", "containerClassName", "customScroll", "withCloseIcon", "withFooter"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function PopupMiniLayout(_ref) {
  var position = _ref.position,
      visible = _ref.visible,
      onClose = _ref.onClose,
      _ref$onCancel = _ref.onCancel,
      onCancel = _ref$onCancel === void 0 ? _noop.noop : _ref$onCancel,
      _ref$onSubmit = _ref.onSubmit,
      onSubmit = _ref$onSubmit === void 0 ? _noop.noop : _ref$onSubmit,
      maskClosable = _ref.maskClosable,
      children = _ref.children,
      className = _ref.className,
      containerClassName = _ref.containerClassName,
      customScroll = _ref.customScroll,
      withCloseIcon = _ref.withCloseIcon,
      withFooter = _ref.withFooter,
      props = _objectWithoutProperties(_ref, _excluded);

  var _useConfig = (0, _configContext.useConfig)(),
      clsPrefix = _useConfig.clsPrefix;

  return /*#__PURE__*/_react.default.createElement(_components.View, _extends({
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup"), className),
    catchMove: true
  }, props), /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__overlay"), {
      'is-shown': visible
    }),
    onClick: function onClick() {
      if (maskClosable) {
        onClose();
      }
    }
  }), customScroll ? /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__container"), containerClassName, position, {
      'is-shown': visible,
      'is-expanded': visible
    })
  }, withCloseIcon && /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__close-icon")),
    onClick: function onClick() {
      onClose();
    }
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
    name: 'CloseOutlined'
  })), children, withFooter && /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__footer"))
  }, /*#__PURE__*/_react.default.createElement(_button.default, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__btn")),
    type: "info",
    onClick: function onClick() {
      onClose();
      onCancel();
    }
  }, "\u53D6\u6D88"), /*#__PURE__*/_react.default.createElement(_button.default, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__btn")),
    type: "primary",
    onClick: function onClick() {
      onSubmit();
    }
  }, "\u786E\u8BA4"))) : /*#__PURE__*/_react.default.createElement(_components.ScrollView, {
    scrollY: true,
    scrollX: false,
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__container"), containerClassName, position, {
      'is-shown': visible,
      'is-expanded': visible
    })
  }, withCloseIcon && /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__close-icon")),
    onClick: function onClick() {
      onClose();
    }
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
    name: 'CloseOutlined'
  })), children, withFooter && /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__footer"))
  }, /*#__PURE__*/_react.default.createElement(_button.default, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__btn")),
    type: "info",
    onClick: function onClick() {
      onClose();
      onCancel();
    }
  }, "\u53D6\u6D88"), /*#__PURE__*/_react.default.createElement(_button.default, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-popup__btn")),
    type: "primary",
    onClick: function onClick() {
      onSubmit();
    }
  }, "\u786E\u8BA4"))));
}